#define _CRT_SECURE_NO_WARNINGS
#include <queue>
using namespace std;
class MyStack {
    queue<int> q1;
    queue<int> q2;
public:
    MyStack() {

    }

    void push(int x) {
        if (!q1.empty())
        {
            q1.push(x);
        }
        else
        {
            q2.push(x);
        }
    }

    int pop() {
        if (q1.empty())
        {
            while (q2.size() != 1)
            {
                q1.push(q2.front());
                q2.pop();
            }
            int res = q2.front();
            q2.pop();
            return res;
        }
        else
        {
            while (q1.size() != 1)
            {
                q2.push(q1.front());
                q1.pop();
            }
            int res = q1.front();
            q1.pop();
            return res;
        }
    }

    int top() {
        if (q1.empty())
        {
            return q2.back();
        }
        else
        {
            return q1.back();
        }
    }

    bool empty() {
        return q1.empty() && q2.empty();
    }
};

/**
 * Your MyStack object will be instantiated and called as such:
 * MyStack* obj = new MyStack();
 * obj->push(x);
 * int param_2 = obj->pop();
 * int param_3 = obj->top();
 * bool param_4 = obj->empty();
 */
int main()
{
    MyStack ms;
    ms.push(1);
    ms.push(2);
    ms.push(3);
    ms.pop();
    ms.pop();
    ms.pop();
    ms.empty();
    return 0;
}